<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<html>
    <script language="JavaScript" type="text/JavaScript">

        window.onload = function()
        {
            document.getElementById("div3").style.display = 'block';
            
            if('${showCusList}' == "true")
            {
                document.getElementById("div3").style.display = 'none';
                window.open ('existingBookings.jsp','_self',false);
                
                alert('<%=request.getAttribute("result")%>');
                window.open('displayCustomerList.jsp?result='+'<%=request.getAttribute("result")%>', 'success', 'width=800,height=350,status=yes,resizable=yes,scrollbars=yes');
            }

            if('${userSession}' ==  "" || '${userSession}' ==  null)
                self.location = "login.jsp";
            

            if(('${airlIdError}' != "" && '${airlIdError}' != null) || ('${jnryDtError}' != "" && '${jnryDtError}' != null))
            {
                document.getElementById("div3").style.display = 'block';
            }
        }
        
        function isValidDate(date)
        {
            var matches = /^(\d{2})[-\/](\d{2})[-\/](\d{4})$/.exec(date);
            if (matches == null) return false;
            var m = matches[2] - 1;
            var d = matches[1];
            var y = matches[3];
            var composedDate = new Date(y, m, d);
            return composedDate.getDate() == d &&
                    composedDate.getMonth() == m &&
                    composedDate.getFullYear() == y;
        }
        
        function isEmpty(str)
        {
            if(str == null || str == "")
                return true;
            else
                return false;
        }
        
        function validateCustomersListPage()
        {
            var airlId = document.getElementsByName("airlId")[0].value;
            var jnryDate = document.getElementsByName("jnryDate")[0].value;
            if(isEmpty(airlId))alert("Please enter AirLine Id.");
            else if(airlId.length != 5  || (!isNaN(airlId)))alert("Please enter valid AirLine Id.");
            else if(isEmpty(jnryDate))alert("Please enter Journey date.");
            else if(!isValidDate(jnryDate)) alert("Please enter Journey date in DD-MM-YYYY format.");
            else document.getElementById("submit").click();
        }
        
    </script>
    <body>
        <form method="post"  action="generateAllCustomerList">
            <h1>Generate Customer List</h1>
          
            <div id="div3">
                <h3>Display Customers List</h3>
                <table cellspacing="10">
                    <tr><td>Enter AirLine Id : </td>
                    <td><input type="text" name="airlId" size="5" maxlength="5" value="${airlId}"/></td><td style="color:red;">${airlIdError}</td></tr>
                    <tr><td>Enter Journey Date : </td>
                    <td><input type="text" name="jnryDate" size="10" maxlength="10" value="${jnryDate}"/></td><td style="color:red;">${jnryDtError}</td></tr>
                </table><br>
            <br>
                <input type="hidden" name="displayCusList" value="displayCusList"/>
                <input type="button" value="Get Customers List" onclick="validateCustomersListPage();"/>    
                <input id="submit" type="submit" name="submit" value="submit"/> 
            </div>
           
        </form>
        
    </body>
</html>